﻿using NUnit.Framework;

namespace OpenWaves.UnitTests
{
    [TestFixture]
    public class UrlPathTests
    {
        [Test]
        public void TestUrlPathEncodesSegments()
        {
            Assert.AreEqual("/elo%20melo/elomelo", UrlPath.Absolute("elo melo", "elomelo").ToString());
        }

        [Test]
        public void TestAbsoluteUrlPathGeneratesRootedPath()
        {
            Assert.AreEqual("/elo/melo", UrlPath.Absolute("elo", "melo").ToString());
        }

        [Test]
        public void TestRelativeUrlPathDoesNotGeneratesRootedPath()
        {
            Assert.AreEqual("elo/melo", UrlPath.Relative("elo", "melo").ToString());
        }

        [Test]
        public void TestGenerateSlugReplacesInvalidCharacters()
        {

            var slug = UrlPath.GenerateSlug("S o<m/e t\\e?xt");


            Assert.AreEqual("S-o-m-e-t-e-xt", slug);
        }

        [Test]
        public void TestGenerateSlugReplacesNationalCharactersToASCIIEquivalents()
        {

            var slug = UrlPath.GenerateSlug("zółć ŻÓŁĆ");


            Assert.AreEqual("zolc-ZOLC", slug);
        }

        [Test]
        public void TestGenerateSlugSkipsSubsequentInvalidCharacters()
        {

            var slug = UrlPath.GenerateSlug("Some<>other???text");


            Assert.AreEqual("Some-other-text", slug);
        }

        [Test]
        public void TestGenerateSlugSkipsInvalidCharactersInPrefix()
        {
            var expectedSlug = "12";
            var acctualSlug = UrlPath.GenerateSlug("$12");

            Assert.AreEqual(expectedSlug, acctualSlug);
        }

        [Test]
        public void TestGenerateSlugSkipsInvalidCharactersInSuffix()
        {
            var expectedSlug = "12";
            var acctualSlug = UrlPath.GenerateSlug("12$");

            Assert.AreEqual(expectedSlug, acctualSlug);
        }

        [Test]
        public void TestPreservingTrailingSlash()
        {
            Assert.AreEqual("/as/", UrlPath.Parse("/as/").ToString());
        }

        [Test]
        public void TestPreservingEmptyPath()
        {
            //required for mailto:aaa@aaa
            Assert.AreEqual("", UrlPath.Parse("").ToString());
        }
    }
}